package edu.ccut.titan.tag.chart.render;

import java.util.HashMap;
import java.util.Map;

import org.jfree.chart.JFreeChart;

import edu.ccut.titan.tag.chart.utils.ChartInfo;

/**
 * 根据注册的ChartRender,获得Chart对象
 * 
 * @author Administrator
 *
 */
public class TitanChartRenderManager {
	
	private static TitanChartRenderManager instance;
	
	private Map<String, ChartRender> renders;
	
	static {
		instance = new TitanChartRenderManager();
	}
	
	private TitanChartRenderManager() {
		initalChartRenderMap();
	}
	
	public static TitanChartRenderManager getInstance() {
		return instance;
	}
	 
	private void initalChartRenderMap() {
		this.renders = new HashMap<String, ChartRender>();
		
		this.renders.put(ChartInfo.BAR_CHART, new BarChartRender());
		this.renders.put(ChartInfo.PIE_CHART, new PieChartRender());
		this.renders.put(ChartInfo.MULTI_PIE_CHART, new MultiplePieChartRender());
		this.renders.put(ChartInfo.LINE_CHART, new LineChartRender());
		this.renders.put(ChartInfo.TIME_SERIES_CHART, new TimeSeriesChartRender());
	}
	
	public JFreeChart getChart(ChartInfo info) {
		if (info != null && this.renders.containsKey(info.getType())) {
			return this.renders.get(info.getType()).buildChart(info);
		}
		
		return null;
	}
	
	public ChartRender getChartRender(String key) {
		return this.renders.get(key);
	}
}
